
#ifndef __TUYA_JSMN_H__
#define __TUYA_JSMN_H__

#include "tuya_cloud_types.h"
#include "tuya_tools.h"

#ifdef __cplusplus
extern "C" {
#endif


#define JSMN_OBJ_ITEM_NUMBER    16
#define JSMN_OBJ_MAX_LEN        (2*1024) 


/**
 * @brief parsing bool type elements in JSON strings
 *
 * @param[in]   json_str: json string to parse
 * @param[in]   key:      JSON key
 * @param[in]   out_value: store the parsed JSON value
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 * 
 * @code Usage
 *  CHAR_T *json_str  = "{\"key1\":\"hello\", \"key2\":1000, \"key3\":true}";
 *  int value;
 *  OPERATE_RET ret;

 *  ret = tuya_json_get_bool_value(json_str, "key3", &value);
 *  if(ret == OPRT_OK) {
 *      app_print("key3's value: %d\n", value); // value_str equ 1
 *  }
 */
OPERATE_RET tuya_json_get_bool_value(const CHAR_T *json_str, CHAR_T *key, INT_T *out_value);


/**
 * @brief parsing int type elements in JSON strings
 *
 * @param[in]   json_str: json string to parse
 * @param[in]   key:      JSON key
 * @param[in]   out_value: store the parsed JSON value
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 * 
 * @code Usage
 *  CHAR_T *json_str  = "{\"key1\":\"hello\", \"key2\":1000, \"key3\":true}";
 *  int value_int;
 *  OPERATE_RET ret;

 *  ret = tuya_json_get_int_value(json_str, "key2", &value_int);
 *  if(ret == OPRT_OK) {
 *      app_print("key2's value: %d\n", value_int); // value_str equ 1000
 *  }
 */
OPERATE_RET tuya_json_get_int_value(const CHAR_T *json_str, CHAR_T *key, INT_T *out_value);

/**
 * @brief parsing string type elements in JSON strings
 *
 * @param[in]   json_str: json string to parse
 * @param[in]   key:      JSON key
 * @param[in]   out_buff: store the parsed JSON string
 * @param[in]   buff_len: length of buff
 *
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 * 
 * @code Usage
 *  CHAR_T *json_str  = "{\"key1\":\"hello\", \"key2\":1000, \"key3\":true}";
 *  CHAR_T value_str[128] = {0};
 *  int value_int;
 *  OPERATE_RET ret;

 *  ret = json_get_str_value(json_str, "key1", value_str, sizeof(value_str));
 *  if(ret == OPRT_OK) {
 *      app_print("key1's value: %s\n", value_str); // value_str equ hello
 *  }
 */
OPERATE_RET tuya_json_get_string_value(const CHAR_T *json_str, CHAR_T *key, CHAR_T *out_buff, UINT16_T buff_len);



#ifdef __cplusplus
}
#endif

#endif
